Skip to content

fix: validate the whole path of a loop item, not only its first segment (#299) - #301

Merged
vaceslav merged 2 commits into
mainfrom
fix/299-validate-item-paths
Dec 1, 2026
Merged

vaceslav merged 2 commits into
mainfrom
fix/299-validate-item-paths

Conversation

@vaceslav

@vaceslav vaceslav commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Description

ValidateTemplate(stream, data) checked a loop item's path only by its first segment. With items that have product.name, both {{line.product.removed}} and {{#if line.product.removed}} inside {{#foreach line in lines}} passed validation; the condition variable was reported by neither validation nor processing.

Validation now resolves the whole path against the loop's items, for values and condition variables, in DOCX and ODT. A path counts as present when any item has it, and a null on the way also counts as present, as in processing. When no item has it, the outer scopes and the data are tried, which is the fallback processing uses.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update

Public API impact: none. Behaviour change of ValidateTemplate with data (to mention in the release notes): a template that reads a nested item path no item has now reports it. A value is reported as a MissingVariable error and listed in MissingVariables; a condition variable is reported as a MissingConditionVariable warning. Processing is unchanged.

Related Issues

Fixes #299
Relates to #261 (the builder's check of stored templates, #294, documented this as a known limit)

Changes Made

  • ScopedVariableValidator.CanResolveInScope (DOCX) and OdtTemplateValidator.CanResolveInScope (ODT) share the new ResolvesOnAnItem. A one-segment path stays as before; a longer path must resolve on an item.
  • Tests: Core/LoopItemPathValidationTests covers both formats:
    • named and implicit items;
    • condition variables;
    • a path present in any item;
    • null on the way;
    • fallback to the data;
    • JSON items.
  • OdtValidationParityTests has a new case for nested item paths, so both formats give the same result.
  • Docs: quick-start.md describes how loop item paths are validated.

Testing

Test Environment

  • .NET 11
  • .NET 10

Tests Added/Updated

  • Unit tests added/updated
  • All existing tests pass: core 2580 + 3 skipped on net11.0 (as before), 2583 on net10.0; Converter 95; Tools 64; format and CI build clean
  • LibreOffice round trips: 15/15 passed, 0 skipped (the change touches OpenDocument/)

Documentation

  • Code comments added/updated
  • Documentation site updated (docs/for-developers/quick-start.md)

Performance Impact

  • No performance impact. Validation now resolves a path per item, and only for multi-segment item paths inside loops.

Breaking Changes

None in the API. The behaviour change is described above and is intended: validation now reports what processing would not find.

…nt (#299)

ValidateTemplate(stream, data) checked a loop item's path ({{line.product.name}},
{{product.name}} inside an unnamed loop) only by its first segment, so a removed
nested field passed validation; a condition variable such a path names was not
reported at all. Now the whole path is resolved against the loop's items, for
values and condition variables, in DOCX and ODT: it counts as present when any
item has it (a null on the way counts too); otherwise the outer scopes and the
data are tried, as processing does.

Behaviour change of ValidateTemplate with data (release notes): templates that
read a nested item path no item has now report it (MissingVariable error for a
value, MissingConditionVariable warning for a condition). Processing is
unchanged; no public API change.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../TriasDev.Templify/Core/ScopedVariableValidator.cs 50.00% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@vaceslav
vaceslav merged commit ca1a1cf into main Dec 1, 2026
12 checks passed
@vaceslav
vaceslav deleted the fix/299-validate-item-paths branch December 1, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValidateTemplate checks only the first segment of a loop item's path

2 participants